/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rw.magallanes.ide.action;

import com.rw.magallanes.core.Warehouse;
import com.rw.magallanes.db.StorageException;
import com.rw.magallanes.ide.main.MainFrame;
import com.rw.magallanes.ide.main.MainSystem;
import com.rw.magallanes.utilities.MessageType;
import com.rw.magallanes.utilities.Utilities;
import java.awt.event.ActionEvent;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractAction;
import javax.swing.KeyStroke;

/**
 *
 * @author Gonzalez
 */
public class SaveAction extends AbstractAction {

    @Override
    public void actionPerformed(ActionEvent e) {

        MainSystem ms = MainSystem.getInstance();
        MainFrame mf = ms.getMainFrame();
        Warehouse wh = mf.getWarehouse();
        try {
            wh.save();
            Utilities.showMsg(mf, "Base de datos almacenada", MessageType.INFO);
        } catch (StorageException ex) {
            Utilities.showMsg(mf, "Error al guardar la base de datos", MessageType.ERROR);
        }

    }

    @Override
    public Object getValue(String key) {
        if (key.compareTo(NAME) == 0) {
            return "Guardar";
        } else if (key.compareTo(ACTION_COMMAND_KEY) == 0) {
            return "save";
        } else if (key.compareTo(ACCELERATOR_KEY) == 0) {
            return KeyStroke.getKeyStroke("ctrl S");
        } else {
            return super.getValue(key);
        }
    }
}
